/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fileNoeud;


import arbre.Element;
import arbre.NoeudFeuille;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author ksz
 */
public class testFileNoeud {

    public testFileNoeud() {
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    @Test
    public void testEstVide() {
         FilePrioriteeDeNoeud file = new FilePrioriteeDeNoeud();

        assertTrue(file.estVide());
    }

    @Test
    public void testEstPasVide() {
        FilePrioriteeDeNoeud file = new FilePrioriteeDeNoeud();

        file.insererPrioritee(new NoeudFeuille(new Element<Character>('a', 15)));

        assertTrue(!file.estVide());
    }

    @Test
    public void testInsererDepiler() {
        FilePrioriteeDeNoeud file = new FilePrioriteeDeNoeud();

        Element elem = new Element<Character>('a', 15);

        file.insererPrioritee(new NoeudFeuille(elem));

        NoeudFeuille nf;
        try {
            nf = (NoeudFeuille) file.depiler();
            assertTrue(nf.getContenu() == elem);
        } catch (NoSuchElementException ex) {
            fail(null);
        }
    }

    @Test
    public void testOrdreCroissant() {
        FilePrioriteeDeNoeud file = new FilePrioriteeDeNoeud();

        for(int i=0; i<100; i++) {
            Element elem = new Element<Character>('a', (int)Math.random());
            file.insererPrioritee(new NoeudFeuille(elem));
        }

        try {
            for(int i=0; i<50; i++) {
                NoeudFeuille nf1;
                NoeudFeuille nf2;
                nf1 = (NoeudFeuille) file.depiler();
                nf2 = (NoeudFeuille) file.depiler();
                assertTrue(nf1.getPrioritee() <= nf2.getPrioritee());
            }
        } catch (NoSuchElementException ex) {
            fail(null);
        }

    }


}